import json
import os

def json_to_snbt(json_file_path, snbt_file_path):
    # Read JSON file
    with open(json_file_path, 'r') as json_file:
        json_data = json.load(json_file)
    
    # Convert JSON to SNBT
    snbt_data = json_to_snbt_recursive(json_data)
    
    # Write SNBT file
    with open(snbt_file_path, 'w') as snbt_file:
        snbt_file.write(snbt_data)

def json_to_snbt_recursive(data):
    if isinstance(data, dict):
        return '{' + ','.join(f'{k}:{json_to_snbt_recursive(v)}' for k, v in data.items()) + '}'
    elif isinstance(data, list):
        return '[' + ','.join(json_to_snbt_recursive(item) for item in data) + ']'
    elif isinstance(data, str):
        return f'"{data}"'
    elif isinstance(data, bool):
        return str(data).lower()
    elif data is None:
        return 'null'
    else:
        return str(data)

def process_directory(input_dir, output_dir):
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    
    for filename in os.listdir(input_dir):
        file_path = os.path.join(input_dir, filename)
        if os.path.isfile(file_path) and filename.endswith('.json'):
            snbt_file_path = os.path.join(output_dir, filename[:-5] + '.snbt')
            json_to_snbt(file_path, snbt_file_path)
            print(f"Converted {filename} to {filename[:-5]}.snbt")
        elif os.path.isdir(file_path):
            process_directory(file_path, os.path.join(output_dir, filename))

# Example usage
input_directory = r'C:/Users/xg200/Desktop/hh1/output1'
output_directory = r'C:/Users/xg200/Desktop/hh1/output2'
process_directory(input_directory, output_directory)